# -*- coding: utf-8 -*-
from argparse import RawTextHelpFormatter, ArgumentParser
from core import BANNER, encrypt, decrypt, genkey

def run():
    parser = ArgumentParser(formatter_class=RawTextHelpFormatter, description=BANNER)
    subparsers = parser.add_subparsers(dest='command', required=True, metavar='COMMANDS')
    key_arg = lambda p: p.add_argument('-k', '--key', default='dcrypt.key', help='Encryption key file path')
    path_arg = lambda p: p.add_argument('path', help='Target directory path')
    encrypt_parser = subparsers.add_parser('encrypt', help='Encrypt a folder')
    key_arg(encrypt_parser)
    path_arg(encrypt_parser)
    encrypt_parser.set_defaults(func=encrypt)
    decrypt_parser = subparsers.add_parser('decrypt', help='Decrypt a folder')
    key_arg(decrypt_parser)
    path_arg(decrypt_parser)
    decrypt_parser.set_defaults(func=decrypt)
    genkey_parser = subparsers.add_parser('genkey', help='Generate encryption key')
    genkey_parser.add_argument('-k', '--key', default='dcrypt.key', help='Encryption key file path')
    genkey_parser.set_defaults(func=genkey)
    args = parser.parse_args()
    args.func(args)

if __name__ == '__main__':
    run()
